package com.office.automate.administration.data.validator;

import java.util.Date;
import java.util.Properties;

import com.office.automate.configuration.property.ConfigurationProperties;
import com.office.automate.exception.administration.BranchExceptionKeys;
import com.office.automate.exception.administration.DivisionExceptionKeys;
import com.office.automate.exception.administration.PublicHolidayExceptionKeys;
import com.office.automate.exception.administration.SecurityLevelExceptionKeys;
import com.office.automate.exception.framework.FrontierVisibleException;
import com.office.automate.frontier.utility.DataConversionUtility;
import com.office.automate.validation.framework.BaseValidator;

public class AdministrationDataValidator extends BaseValidator {

	private Properties configurations = ConfigurationProperties.getProps();
	private DataConversionUtility dataConversionUtility = new DataConversionUtility();

	protected void validateSecurityLevelDescription(String aSecurityLevelDescription) {
		if (aSecurityLevelDescription == null || aSecurityLevelDescription.isEmpty()) {
			addFieldValidationException("roledescription", new FrontierVisibleException(SecurityLevelExceptionKeys.SECURITY_LEVEL_DESCRIPTION_IS_EMPTY, null));
		}else if (aSecurityLevelDescription.length() > dataConversionUtility.convertStringToNumber(configurations.getProperty("SECURITY_LEVEL_DESCRIPTION_LENGTH"))) {
			addFieldValidationException("roledescription", new FrontierVisibleException(SecurityLevelExceptionKeys.EXCEEDS_DESCRIPTION_LENGTH, null));
		}
	}

	protected void validateBranchDescription(String aBranchDescription) {
		if (aBranchDescription == null || aBranchDescription.isEmpty()) {
			addFieldValidationException("branchdescription", new FrontierVisibleException(BranchExceptionKeys.BRANCH_DESCRIPTION_IS_EMPTY, null));
		}else if (aBranchDescription.length() > dataConversionUtility.convertStringToNumber(configurations.getProperty("BRANCH_DESCRIPTION_LENGTH"))) {
			addFieldValidationException("branchdescription", new FrontierVisibleException(BranchExceptionKeys.EXCEEDS_BRANCH_DESCRIPTION_LENGTH, null));
		}
	}

	protected void validateBranchLocationDescription(String aBranchLocationDescription) {
		if (aBranchLocationDescription == null || aBranchLocationDescription.isEmpty()) {
			addFieldValidationException("branchlocation", new FrontierVisibleException(BranchExceptionKeys.BRANCH_LOCATION_DESCRIPTION_IS_EMPTY, null));
		}else if (aBranchLocationDescription.length() > dataConversionUtility.convertStringToNumber(configurations.getProperty("BRANCH_LOCATION_DESCRIPTION_LENGTH"))) {
			addFieldValidationException("branchlocation", new FrontierVisibleException(BranchExceptionKeys.EXCEEDS_LOCATION_LENGTH, null));
		}
	}

	protected void validateBranchManager(long aBranchManager) {
		if (aBranchManager == 0) {
			addFieldValidationException("managerorsupervisor", new FrontierVisibleException(BranchExceptionKeys.MANAGER_IS_NOT_SET, null));
		}
	}

	protected void validateSecurityLevel(int aSecurityLevelId) {
		if (aSecurityLevelId == 0) {
			addFieldValidationException("securityLevel", new FrontierVisibleException(SecurityLevelExceptionKeys.SECURITY_LEVEL_IS_NOT_SET, null));
		}
	}

	protected void validateUseOfSecurityLevel(int aSecurityLevelId) {
		
	}

	protected void validateDivisionName(String aDivisionName) {
		if (aDivisionName == null || aDivisionName.isEmpty()) {
			addFieldValidationException("divisionname", new FrontierVisibleException(DivisionExceptionKeys.DIVISION_NAME_IS_EMPTY, null));
		}else if (aDivisionName.length() > dataConversionUtility.convertStringToNumber(configurations.getProperty("DIVISION_NAME_LENGTH"))) {
			addFieldValidationException("divisionname", new FrontierVisibleException(DivisionExceptionKeys.EXCEEDS_DIVISION_NAME_LENGTH, null));
		}
	}

	protected void validateDivisionDescription(String aDivisionDescription) {
		if (aDivisionDescription == null || aDivisionDescription.isEmpty()) {
			addFieldValidationException("divisiondescription", new FrontierVisibleException(DivisionExceptionKeys.DIVISION_DESCRIPTION_IS_EMPTY, null));
		}else if (aDivisionDescription.length() > dataConversionUtility.convertStringToNumber(configurations.getProperty("DIVISION_DESCRIPTION_LENGTH"))) {
			addFieldValidationException("divisiondescription", new FrontierVisibleException(DivisionExceptionKeys.EXCEEDS_DIVISION_DESCRIPTION_LENGTH, null));
		}
	}

	protected void validateHolidayType(String aHolidayType) {
		if (aHolidayType == null || aHolidayType.isEmpty()) {
			addFieldValidationException("holidayType", new FrontierVisibleException(PublicHolidayExceptionKeys.HOLIDAY_TYPE_IS_EMPTY, null));
		}
	}

	protected void validateHolidayDescription(String aHolidayDescription) {
		if (aHolidayDescription == null || aHolidayDescription.isEmpty()) {
			addFieldValidationException("holidaydescription", new FrontierVisibleException(PublicHolidayExceptionKeys.HOLIDAY_DESCRIPTION_IS_EMPTY, null));
		}else if (aHolidayDescription.length() > dataConversionUtility.convertStringToNumber(configurations.getProperty("PUBLIC_HOLIDAY_DESCRIPTION_LENGTH"))) {
			addFieldValidationException("holidaydescription", new FrontierVisibleException(PublicHolidayExceptionKeys.EXCEEDS_HOLIDAY_DESCRIPTION_LENGTH, null));
		}
	}

	protected void validateExistanceOfHoliday(Date aHolidayDate) {
		if (aHolidayDate == null) {
			addFieldValidationException("StartDate", new FrontierVisibleException(PublicHolidayExceptionKeys.HOLIDAY_DATE_IS_NOT_SET, null));
		}else if (isDateAlreadyAdded(aHolidayDate)) {
			addFieldValidationException("StartDate", new FrontierVisibleException(PublicHolidayExceptionKeys.HOLIDAY_DATE_IS_ALREADY_EXIST, null));
		}
	}

	private boolean isDateAlreadyAdded(Date aHolidayDate) {
		 //TODO: Need to add validation logics
		
		return false;
	}
}
